#pragma once
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
#define Path "./fifo"
#define Mode 0666
//希望这个类帮助我们来完成创建管道文件
class Fifo
{
public:
    Fifo(string&& pathname)
        : _pathname(pathname)
    {
        umask(0);
        int n = mkfifo(_pathname.c_str(), Mode);
        if(n == -1)
        {
            cout << "create pipe file fail" << endl;
            cerr << "errno : " << errno << ", strerror : " << strerror(errno) << endl;
            exit(-1);
        }
        cout << "create pipe file success" << endl;
    }
    ~Fifo()
    {
        unlink(GetString());
    }

    const char* GetString()
    {
        return _pathname.c_str();
    }
private:
    string _pathname;
};